package com.lonewalker.completablefuturedemo;

import java.util.concurrent.CompletableFuture;

/**
 * @author LoneWalker
 * @date 2023/2/12
 * @description
 */
public class demo7 {
    public static void main(String[] args) {
        CompletableFuture<String> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("1号任务执行");
            return "hello";
        });

        CompletableFuture<String> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("2号任务执行");
            return ",CompletableFuture";
        });

        CompletableFuture<String> completableFuture3 = completableFuture2.thenCombine(completableFuture1, (result1, result2) -> {
            return result2 + result1;
        });
        System.out.println(completableFuture3.join());

        CompletableFuture<String> completableFuture4 = completableFuture1.thenCombine(completableFuture2, (result1, result2) -> {
            return result1 + result2;
        });
        System.out.println(completableFuture4.join());

    }
}
